/*
 * util.c
 *
 *  Created on: 2012-8-4
 *      Author: wx
 */
#include <stdio.h>
#include <arpa/inet.h>
#include <time.h>

const char * GetIPStr(unsigned int ipaddr)
{
	static char IPStr[16];
	inet_ntop(AF_INET, (void*)&ipaddr, IPStr, 16);
	return IPStr;
}

//转换时间为字符串，格式 yyyy-MM-dd HH:mm:ss.uuuuuuu
//返回指针为静态指针，不能释放。
const char * GetTimeStr(int sec, int usec)
{
	static char sTime[32];
	static char buf[32];
	static time_t curtime;
	struct tm * loctime;

	curtime = sec;
	loctime = localtime(&curtime);
	strftime(buf, 32, "%Y-%m-%d %H:%M:%S.", loctime);
	sprintf(sTime, "%s%06d", buf, usec);
	return sTime;
}


